//
//  SEGFaceRecognitionManager.m
//  SEGModel
//
//  Created by 乔杨 on 2020/7/6.
//

#import "SEGFaceRecognitionManager.h"

@implementation SEGFaceRecognitionManager

/// 上传人脸识别照片
/// @param facePath   //类型：String  必有字段  备注：图片地址
/// @param finished 回调
- (void)seg_saveFacePath:(NSString *)facePath finished:(SEGRequestCallBack)finished {
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL, @"/", kUhomecp_sso, @"/v2/userApp/saveFacePath", nil];
    NSDictionary *params = @{@"custId":kAccountCustId,
                             @"userId":kAccountUserID,
                             @"communityId":kAccountCommunityID,
                             @"facePath":facePath
                            };
    
    [SEGHTTPBusinessManager seg_requestJSONWithMethod:POST URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        if (!isSuccessed) {
            finished(NO, codeType, errorMessage);
            return;
        }
        
        finished(YES, codeType, errorMessage);
    }];
}

/// 查询人脸识别照片
/// @param finished 回调
- (void)seg_queryFacePathWithFinished:(SEGRequestCallBack)finished {
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL, @"/", kUhomecp_sso, @"/v2/userApp/queryFacePath", nil];
    NSDictionary *params = @{@"custId":kAccountCustId};
    [SEGHTTPBusinessManager seg_requestJSONWithMethod:GET URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        if (!isSuccessed) {
            finished(NO, codeType, errorMessage);
            return;
        }
        
        NSDictionary *dataDict = [result valueForKey:@"data"];
        if (!dataDict || ![dataDict isKindOfClass:[NSDictionary class]]) {
            finished(NO, codeType, errorMessage);
            return;
        }
        
        self.facePath = dataDict[@"facePath"];
        finished(YES, codeType, errorMessage);
    }];
}

@end
